package cn.csxw.openchina.dagger2.presenter;

import java.util.ArrayList;

import javax.inject.Inject;

import cn.csxw.openchina.entity.bean.NewsBean;
import cn.csxw.openchina.entity.bean.OsChinaBean;
import cn.csxw.openchina.ui.fragment.syntheticalFragment.InformationFragment;
import retrofit2.Call;

/**
 * 综合模块的资讯界面的Presenter类
 */

public class NewsPresenter extends BasePresenter {

    InformationFragment informationFragment;

    @Inject
    public NewsPresenter(InformationFragment informationFragment){
        this.informationFragment = informationFragment;
    }

    @Override
    public void processData(OsChinaBean data) {
        if (data != null){
           if(!hasMoreData(data)){
               informationFragment.noMoreData();
               informationFragment.mSrfLayout.setRefreshing(false);
           }else{
               ArrayList<NewsBean> newsList = (ArrayList<NewsBean>) data.newslist;
               if( informationFragment.mInformationAdapter.getData().size()!=0){
                   informationFragment.mInformationAdapter.addData(newsList);
               }else{
                   informationFragment.mInformationAdapter.setData(newsList);
               }
               informationFragment.loadMoreCompleted();
               informationFragment.mSrfLayout.setRefreshing(false);
           }
        }
    }
    @Override
    public void callNetWork(Object... params) {
        if(params.length!=3||!(params[0] instanceof Integer)
                ||!(params[1] instanceof Integer)||!(params[2] instanceof Integer)){
            throw new IllegalArgumentException("参数必需是String , int ,int,三个类型");
        }
        Call<OsChinaBean> newsInfo = mOsChinaServer.getNewsInfo((int)params[0],(int)params[1],(int)params[2]);
        newsInfo.enqueue(mCallback);
    }
}
